<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>聊天记录</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/animate.css" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox chat-view">
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-md-9 ">
                            <div id="chatlog">

                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
<script src="__PUBLIC__/im/js/content.min.js?v=1.0.0"></script>
<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
<script src="__PUBLIC__/layui/layui.js"></script>
<script type="text/javascript">
    $(function(){
        $.getJSON("{:url('Im/userChatLog')}", {'id' : '{$chatToken}', 'type' : "friend"}, function(res){
            var _html = '';
            if( 1 == res.code ){
                $.each(res.data, function(k, v){
                    console.log(parent.layui.layim.content(v.message))
                    _html += '<div class="chat-message"><div class="message"><a class="message-author" href="#"><img style="width: 30px;height: 30px; border-radius: 30px;" src="'+v.from_user.avatar+'"> '+ v.from_user.user_name +' </a>';
                    _html += '<span class="message-date"> '+ getLocalTime(v.createtime) +' </span>';
                    _html += '<div class="message-content" style="margin-top: 5px;">'+parent.layui.layim.content(v.message)+'</div></div></div>';
                });
                $("#chatlog").html(_html);

            }else{

            }
        })
    });
    function getLocalTime(nS) {
        return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, "");
    }
</script>
</body>
</html>